package com.wens.monitor.util;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class LRU implements ReplaceStrategy {
	private Map<Object, Long> usedCount = new HashMap<Object, Long>();
	
	@Override
	public void get(Object key) {
		usedCount.put(key, System.currentTimeMillis());
	}

	@Override
	public Object getRemoveKey() {
		long max = 0;
		Object key = null;
		for (Object k : usedCount.keySet()) {
			long distance = System.currentTimeMillis() - usedCount.get(k);
			if (distance > max ){
				max = distance;
				key = k;
			}
		}
		return key;
	}

	@Override
	public void remove(Object key) {
		usedCount.remove(key);
	}

}
